/**
 * Created by PengWei on 2018/7/26.
 */

namespace mengdao {
    import getTimer = egret.getTimer;
    export class TimeGetter {
        private static _serverTimeStamp: number;
        private static _localTimeStamp: number;
        private static _timeZoneOffset: number;

        public static set serverTime(v: number) {
            this._serverTimeStamp = v;
            this._localTimeStamp = getTimer();
        }

        public static get serverTime(): number {
            return getTimer() - this._localTimeStamp + this.timeZoneOffset;
        }

        public static get timeZoneOffset(): number {
            if (isNaN(this._timeZoneOffset)) {
                let date = new Date();
                this._timeZoneOffset = date.getTimezoneOffset() * 60000;
            }
            return this._timeZoneOffset;
        }
    }
}